package com.bm.specialvehiclefordispatcher.activity.setting;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.bm.corelibs.logic.BaseLogic.NListener;
import com.bm.corelibs.utils.ToastMgr;
import com.bm.specialvehiclefordispatcher.R;
import com.bm.specialvehiclefordispatcher.activity.BaseActivity;
import com.bm.specialvehiclefordispatcher.bean.BaseData;
import com.bm.specialvehiclefordispatcher.constants.Constant;
import com.bm.specialvehiclefordispatcher.logics.SettingManager;
import com.bm.specialvehiclefordispatcher.views.CommonNavigationBar;

/**
 * @Copyright Copyright 2014 蓝色互动. All rights reserved.
 * 
 * @author GuoHao
 * @Date: 2015年8月24日 客服咨询
 */
public class HotlineCounselingActivity extends BaseActivity {
	RelativeLayout hotline_layout;
	CommonNavigationBar bar;
	TextView hotline_call;
	String phone;
	SettingManager manager = new SettingManager();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_hotlinecounseling);
		findViews();
		init();
		addListeners();
	}

	@Override
	public void findViews() {
		bar = (CommonNavigationBar) findViewById(R.id.navi);
		hotline_layout = (RelativeLayout) findViewById(R.id.hotline_layout);
		hotline_call = (TextView) findViewById(R.id.hotline_call);
	}

	@Override
	public void init() {
		bar.setTitle("客服咨询");
		bar.setListener(null);
		loadingDialog.show();
		manager.getHotLine(getCancelListener());
	}
	
	private NListener<BaseData> getCancelListener() {
		return new NListener<BaseData>() {
			@Override
			public void onResponse(BaseData data) {
				loadingDialog.dismiss();
				if (data.status == Constant.STATUS_OK) {
					if(data.data.param != null) {
						phone = data.data.param.value;
						hotline_call.setText(data.data.param.value);
					}
				} else {
					ToastMgr.show(data.msg);
				}
			}

			@Override
			public void onErrResponse(VolleyError error) {
				loadingDialog.dismiss();
			}

			@Override
			public void onAllPageLoaded(int nowPage, int totalPage) {
			}
		};
	}

	@Override
	public void addListeners() {
		hotline_layout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
				startActivity(callIntent);
			}
		});
	}

}
